

import {food_like_list} from '../../network/interface'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    likeList: [],
    sumPrice:0
  },
  removeShop: function(e){
    var index = e.currentTarget.dataset.value;
    var array = this.data.likeList;
    var sumPrice = this.data.sumPrice;
    var subtotal = parseFloat((array[index].amount * array[index].price).toFixed(1));
    sumPrice = parseFloat((Number(sumPrice) - Number(subtotal)).toFixed(1));
    this.data.likeList.splice(index,1)
    this.setData({
        sumPrice:sumPrice,
        likeList: getApp().arrayLikeList 
      });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.getLikeList();
  },

  getLikeList(){
    let params={}
    wx.showLoading(
      {
        title:"加载中"
      }
    )
    food_like_list(params,res=>{
      console.log(res)
      this.setData({
        likeList:res.data
      })
      wx.hideLoading({
        success: (res) => {},
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  toDetail(e){
    console.log(e.currentTarget.dataset.id)
    var id=e.currentTarget.dataset.id
    wx.redirectTo({
      url: '../foodIntroduce/foodIntroduce?id='+id
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({likeList: getApp().arrayLikeList });
    var likeList = this.data.likeList;
    var tempPrice = 0;
    for (var temp in likeList) {
      tempPrice = parseFloat((Number(tempPrice) + Number(likeList[temp].subtotal)).toFixed(1));
    }
    
    this.setData({ sumPrice: tempPrice });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})